package com.compus.task;

import com.compus.entity.po.CarPosition;
import com.compus.service.CarPositionService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

//@Component
public class PositionMockTask {

    List<String> list = Arrays.asList("104.59153,31.45715",
            "104.592356,31.456532", "104.59175,31.455763",
            "104.593649,31.454624","104.594271,31.455393",
            "104.601164,31.453475","104.597318,31.455297",
            "104.604458,31.450986","104.597265,31.452496",
            "104.595366,31.454674","104.597361,31.457081");

    Long carId = 1766843038979743744L;

    @Resource
    private CarPositionService carPositionService;
    @Scheduled(cron = "10/5 * * * * ?")
    public void mockPosition() {
        int index = new Random().nextInt(list.size());
        String position = list.get(index);
        CarPosition carPosition = new CarPosition();
        carPosition.setCarId(carId);
        carPosition.setPosition(position);
        carPosition.setCreateTime(LocalDateTime.now());
        carPositionService.save(carPosition);
    }

}
